package servlet.personage;

import data.Insert;
import data.Select;
import servlet.Control;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "InsertReview",value = "/personage/insertReview")
public class InsertReview extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String tid=request.getParameter("id");
        String title=request.getParameter("title");
        String content=request.getParameter("content");

        //先查询review的数目，如果超过10个则不允许继续增加
        if(Select.reviewNumber(tid)>=10){
            Control.fail(response);
            return;
        }

        Control.simpleSend(Insert.review(tid,title,content),response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
